#include <iostream>

// 服务器接口
class Server
{
public:
    virtual ~Server() = default;
    virtual void request() = 0;
};

// 真实服务
class RealServer : public Server
{
public:
    void request() override
    {
        std::cout << "RealServer request" << std::endl;
    }
};

// 代理服务器
class Proxy : public Server
{
    RealServer *realServer;

public:
    Proxy() : realServer(nullptr) {}
    ~Proxy()
    {
        delete realServer;
    }
    bool checkAccess()
    {
        std::cout << "Proxy check access" << std::endl;
        return true;
    }
    void request() override
    {
        if (!realServer)
        {
            realServer = new RealServer();
        }
        if (checkAccess())
        {
            realServer->request();
        }
    }
};
